package org.csu.mypetstore.exception;

import org.csu.mypetstore.common.CommonResponse;
import org.mybatis.logging.Logger;
import org.mybatis.logging.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


@RestControllerAdvice
public class GlobalExceptionAdvice {

    private static final Logger LOG = LoggerFactory.getLogger(GlobalExceptionAdvice.class);

    @ExceptionHandler(value = TokenException.class)
    public CommonResponse<String> handleException(Exception e){
        if (e instanceof TokenException){
            TokenException tokenException = (TokenException) e;
            return CommonResponse.createForError(tokenException.getStatus(), tokenException.getMsg());
        }else {
            return CommonResponse.createForError("未知异常");
        }
    }
}
